package signalx

import (
	"fmt"
	"os"
	"os/signal"
	"syscall"
)

// WaitSignal register signals Handler.
// https://blog.csdn.net/js_xj/article/details/6692440?locationNum=6&fps=1
func WaitSignal(handler func()) {

	c := make(chan os.Signal, 1)
	signal.Notify(c, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT /*, syscall.SIGSTOP*/, syscall.SIGABRT, syscall.SIGKILL)
	for {
		s := <-c

		switch s {
		case syscall.SIGQUIT, syscall.SIGTERM /*syscall.SIGSTOP, */, syscall.SIGINT, syscall.SIGABRT, syscall.SIGKILL:
			handler()
		case syscall.SIGHUP:
			handler()
		default:
		}

		fmt.Println("signal exit: ", s.String())
		os.Exit(0)
	}
}

func reload() {
}
